
<template>
	<!-- 考勤-晨检-记录晨检信息 -->
	<div>
		<el-row>
			<el-col :span="4">
				<span class="formLable">导入文件</span>
			</el-col>
			<el-col :span="20">
				<el-input disabled placeholder="请上传文件" v-model="saveParam.fileUrl">
					<el-button type="primary" slot="append" @click="activeUpload">选择文件</el-button>
				</el-input>
			</el-col>
		</el-row>
		<el-row>
			<el-col :span="4">
				<p></p>
			</el-col>
			<el-col :span="20">
				<span class="formLable">注：首次上传，请下载
					<el-link type="primary" href="https://element.eleme.io" target="_blank">导入模板</el-link>
				</span>
			</el-col>
		</el-row>
		<el-row style="text-align:center;">
			<el-button @click="cancle">取消</el-button>
			<el-button @click="save">确定导入</el-button>
		</el-row>
		<input style="display:none;" type="file" id="morningcheck-input" name="files">
	</div>
</template>

<script>
	let vm;
	export default{
		components:{},
		data(){
			return {
				saveParam:{
					fileUrl:'',
				},
			}
		},
		methods:{
			init(data){
				
			},
			cancle(){
				this.$emit('cancle',false);
			},
			save(){
				
				this.$emit('cancle',false);
			},
			activeUpload(){
				document.querySelector('#morningcheck-input').click();
			},
			upload(e){
				
				var files =e.target.files;
				let file = files[0];
				var dx =(file.size/1024)/1024;
				if(dx>2){
					vm.$message({
						message: '单张图片最大不能超过2M，请重新选择图片！',
						type: 'warning'
					});
					return;
				}
				let filedata = new FormData(); //创建form对象
				filedata.append("file", file, file.name); //通过append向form对象添加数据
				filedata.append("content", "morningcheck"); //添加form表单中其他数据
				api.uploadFile(filedata).then(function(d) {
					if (d.result = "操作成功") {
						vm.saveParam.fileUrl=d.url;
					}
				});
			},
		},
		mounted(){
			vm=this;
			document.getElementById("morningcheck-input").addEventListener('change',this.upload);
		},
		computed:{
			
		},
		watch:{

		}
	}
</script>

<style lang="scss" scoped>
	.formLable,.formValue{
		font-size: 0.16rem;
		line-height: 0.4rem;
	}
	.formLable.must::before{
		content: '*';
		color: red;
		margin: 0 0.05rem;
	}
	.el-row{
		margin-bottom: 0.16rem;
	}
	.el-checkbox{
		font-size: 0.16rem;
		line-height: 0.4rem;
	}
	.el-radio{
		font-size: 0.16rem;
		line-height: 0.4rem;
	}
</style>